package main

import (
	"fmt"
	"reflect"
)

type node2 struct {
	_    int
	id   int
	next *node2
}

type Response struct {
	Code string     `json:"code"`
	Msg  string     `json:"msg"`
	Data [][]string `json:"data"`
}

func main() {
	//n1 := node2{
	//	id: 1,
	//}
	//
	//n2 := node2{
	//	id:   2,
	//	next: &n1,
	//}

	//fmt.Println(n1, n2)

	res := Response{
		Code: "-1",
		Msg:  "fail",
		Data: nil,
	}
	fmt.Println(res)

	//匿名结构体变量
	u := struct {
		name string
		age  byte
	}{
		name: "haha",
		age:  12,
	}

	//匿名结构体类型字段
	type file struct {
		name string
		attr struct {
			owner int
			perm  int
		}
	}
	f := file{
		name: "test.txt",
		//attr: struct {
		//	owner int
		//	perm  int
		//}{owner: 1, perm: 0755},
	}
	f.attr.owner = 1
	f.attr.perm = 0755
	fmt.Println(u, f)

	//structsTest1()
	structsTag()
}

func structsTest1() {
	exit := make(chan struct{})
	go func() {
		println("hello wold")
		exit <- struct{}{}
	}()
	<-exit
	println("end")
}

//tag
func structsTag() {
	type user struct {
		name string `昵称`
		sex  byte   `性别`
	}

	u := user{"tom", 1}
	v := reflect.ValueOf(u)
	t := v.Type()

	for i, n := 0, t.NumField(); i < n; i++ {
		fmt.Printf("%s:%v\n", t.Field(i).Tag, v.Field(i))
	}

}
